package cn.com.dhc.danlu.widget.adapter;

import android.support.annotation.NonNull;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

/**
 * User: Geek_Soledad(wuhaiyang@danlu.com)
 * Date: 2016-09-23
 * Time: 16:56
 * Description: .....
 */
public abstract class BaseRecyclerviewAdapter <VH extends XRecyclerView.ViewHolder> extends XRecyclerView.Adapter<VH> {
    private List mDatas;

    protected BaseRecyclerviewAdapter() {
    }

    public void refreshAllData(@NonNull List datas) {
        if (null != this.mDatas) {
            mDatas = null;
        }
        this.mDatas = datas;
        notifyDataSetChanged();
    }

    public void appendData(@NonNull List datas) {
        int prevIndex = getItemCount();
        mDatas.addAll(datas);
        notifyItemRangeInserted(prevIndex + 1, mDatas.size());
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public List getDatas() {
        return mDatas;
    }

    public void refreshItem(int pos) {
        notifyItemChanged(pos);
    }

    public Object getItemByPos(int pos) {
        return mDatas.get(pos);
    }
}
